<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class DatabaseTransaction extends ADODBDatabase {
	
	//constructor
	function DatabaseTransaction() {
		parent::ADODBDatabase();
	}
	
	//methods
	function startTransaction() {
		$this->checkConnection();
		if( $this->_transaction == 0 ) {
			mysql_query('START TRANSACTION', ${$this->_link});
		}
		$this->_transaction = 1;
	}
	
	function commit() {
		if( $this->_transaction > 0 ) {
			$result = mysql_query('COMMIT', ${$this->_link});
			$this->_transaction = 0;
			if( !$result ) {
				$this->error('COMMIT');
			}
		}
		
		return true;
	}
	
	function rollback() {
		if( $this->_transaction > 0 ) {
			$result = mysql_query('ROLLBACK', ${$this->_link});
			$this->_transaction = 0;
			if( !$result ) {
				$this->error('COMMIT');
			}
		}
		
		return true;
	}
}
//
?>